package com.link2room.aeriabots.thread.task;


import com.link2room.aeriabots.dto.result.base.WxMemberInfoResDto;
import com.link2room.aeriabots.facade.IWXMemberInfoFacadeService;
import com.link2room.aeriabots.feign.rodimus.SalesmansFeignService;
import com.link2room.aeriabots.thread.TaskResult;
import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.util.ClassConverUtil;
import com.link2room.common.util.SpringUtil;
import com.link2room.rodimus.dto.param.base.SalesmanAwardMemberParamDto;
import com.link2room.rodimus.dto.result.base.WxMemberInfoDto;

import java.util.List;
import java.util.concurrent.Callable;

/**
 * Created by LN on 2016/10/31.
 */
public class AwardSalesmanMemberTask implements Callable<TaskResult> {
    private SalesmansFeignService salesmansFeignService;
    private SalesmanAwardMemberParamDto paramDto;
    private IWXMemberInfoFacadeService wxMemberInfoFacadeService;
    public AwardSalesmanMemberTask(SalesmanAwardMemberParamDto paramDto){
        //rodimusAPIService = (IRodimusAPIService) SpringUtil.getBean("rodimusAPIService");
        wxMemberInfoFacadeService = (IWXMemberInfoFacadeService) SpringUtil.getBean("wxMemberInfoFacadeService");
        salesmansFeignService =  SpringUtil.getBean(SalesmansFeignService.class);
        this.paramDto = paramDto;
    }
    @Override
    public TaskResult call() throws Exception {
        TaskResult result = new TaskResult();
        try{
            BaseL2rParamDto memberInfoParamDto = new BaseL2rParamDto();
            memberInfoParamDto.setOpenid(paramDto.getOpenId());
            memberInfoParamDto.setLhotelGroupCode(paramDto.getLhotelGroupCode());
            List<WxMemberInfoResDto> res = wxMemberInfoFacadeService.getMemberInfos(memberInfoParamDto);
            if(res != null && res.size() != 0){
                paramDto.setWxMemberInfo(ClassConverUtil.copyProperties(res.get(0), WxMemberInfoDto.class));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        try {

            salesmansFeignService.awardSalesmanMember(paramDto);
            result.setResultCode(TaskResult.SUCCESS);
        }
        catch (Exception e){
            result.setResultCode(TaskResult.ERROR);
            result.setResultMessage("Task had Exception:"+e.getMessage());
            result.setException(e);
        }
        return result;
    }
}
